package org.msss.sprites;

import org.msss.gamebasic.*;
import org.lwjgl.input.Mouse;

public class MouseGrid extends Sprite {
	
	private int mouseGridX, mouseGridY;
	private static final int GRID_WIDTH = Frame.WINDOW_WIDTH / 3;
	private static final int GRID_HEIGHT = Frame.WINDOW_HEIGHT / 3;
	
	public void move() {
		
		if (getDirection() == 0) {
			if (Mouse.getX() >= GRID_WIDTH * 2) {
				mouseGridX = 2;
			} else if (Mouse.getX() >= GRID_WIDTH) {
				mouseGridX = 1;
			} else {
				mouseGridX = 0;
			}
			
			if (Mouse.getY() >= GRID_HEIGHT * 2) {
				mouseGridY = 2;
			} else if (Mouse.getY() >= GRID_HEIGHT) {
				mouseGridY = 1;
			} else {
				mouseGridY = 0;
			}
		} else if (getDirection() == 180) {
			if (Mouse.getX() >= GRID_WIDTH * 2) {
				mouseGridX = 0;
			} else if (Mouse.getX() >= GRID_WIDTH) {
				mouseGridX = 1;
			} else {
				mouseGridX = 2;
			}
			
			if (Mouse.getY() >= GRID_HEIGHT * 2) {
				mouseGridY = 0;
			} else if (Mouse.getY() >= GRID_HEIGHT) {
				mouseGridY = 1;
			} else {
				mouseGridY = 2;
			}
		} else if (getDirection() == 90) {
			if (Mouse.getX() >= GRID_WIDTH * 2) {
				mouseGridY = 0;
			} else if (Mouse.getX() >= GRID_WIDTH) {
				mouseGridY = 1;
			} else {
				mouseGridY = 2;
			}
			
			if (Mouse.getY() >= GRID_HEIGHT * 2) {
				mouseGridX = 2;
			} else if (Mouse.getY() >= GRID_HEIGHT) {
				mouseGridX = 1;
			} else {
				mouseGridX = 0;
			}
		} else if (getDirection() == 270) {
			if (Mouse.getX() >= GRID_WIDTH * 2) {
				mouseGridY = 2;
			} else if (Mouse.getX() >= GRID_WIDTH) {
				mouseGridY = 1;
			} else {
				mouseGridY = 0;
			}
			
			if (Mouse.getY() >= GRID_HEIGHT * 2) {
				mouseGridX = 0;
			} else if (Mouse.getY() >= GRID_HEIGHT) {
				mouseGridX = 1;
			} else {
				mouseGridX = 2;
			}
		}
	}
	
	public int getMGX() {
		return mouseGridX;
	}
	
	public int getMGY() {
		return mouseGridY;
	}
}
